<template>
  <view class="page-business">
    <view class="b-w inner" :style="{ minHeight: `calc(100vh - ${headerHeight}rpx - 120rpx)` }">
      <view class="header-my">
        <view class="fail-reason f32" v-if="detail.failReason && detail.audit == 2"
          >拒绝原因：{{ detail.failReason }}</view
        >
        <view class="title f32" @click="handleNavEnterDetail">{{ detail.enterpriseName }}</view>
        <view class="tags-list">
          <view class="flex-x-c tags-item">
            <u-icon class="tags-icon" size="18" name="tags"></u-icon>
            <view class="fc-66">{{ detail.industry }}</view>
          </view>
          <view class="flex-x-c tags-item" v-if="detail.enterpriseArea">
            <u-icon class="tags-icon" size="18" name="map"></u-icon>
            <view class="fc-66">{{ detail.enterpriseArea }}</view>
          </view>
        </view>
      </view>
      <view class="content-word" v-if="detail.content">
        {{ detail.content }}
      </view>
    </view>
    <view class="foot-bar flex-x-c">
      <view class="flex-y-c item-left" @click="goChat">
        <u-icon class="tags-icon" size="25" name="chat"></u-icon>
        <view class="f24">留言</view>
      </view>
      <view class="flex-x-c" v-if="identifying == 'admin'">
        <u-button
          v-if="detail.audit == 0"
          class="btn"
          type="success"
          text="通过"
          customStyle="marginRight: 20rpx"
          @click="auditPub(1)"
        ></u-button>
        <u-button
          v-if="detail.audit == 0"
          class="btn"
          type="warning"
          text="拒绝"
          customStyle="marginRight: 20rpx"
          @click="refuseBtn"
        ></u-button>
        <u-button
          v-if="detail.audit == 1"
          class="btn"
          type="warning"
          @click="handleOutShelf"
          text="下架"
          customStyle="marginRight: 20rpx"
        ></u-button>
        <u-button
          v-if="detail.audit == 1 || detail.audit == 2"
          class="btn"
          @click="handleDelete"
          text="删除"
          customStyle="marginRight: 20rpx"
        ></u-button>
      </view>
      <view
        class="flex-x-c"
        v-if="identifying == 'enterprise' && detail.userId === userInfoDetail.userId"
      >
        <u-button
          v-if="detail.audit == 2"
          class="btn"
          type="info"
          text="编辑"
          customStyle="marginRight: 20rpx"
        ></u-button>
        <u-button
          v-if="detail.audit == 1"
          class="btn"
          type="warning"
          @click="handleOutShelf"
          text="下架"
          customStyle="marginRight: 20rpx"
        ></u-button>
        <u-button
          v-if="detail.audit == 1 || detail.audit == 2"
          class="btn"
          @click="handleDelete"
          text="删除"
          customStyle="marginRight: 20rpx"
        ></u-button>
      </view>
    </view>
    <u-modal
      :show="show"
      title="审核不通过"
      showCancelButton
      @confirm="confirmBtn"
      @cancel="cancelBtn"
    >
      <view class="slot-content" style="width: 100%">
        <u--textarea
          v-model="failReason"
          placeholder="请输入拒绝理由"
          count
          maxlength="100"
        ></u--textarea>
      </view>
    </u-modal>
    <public-dialog ref="dialog"></public-dialog>
  </view>
</template>

<script>
export default {
  data() {
    return {
      headerHeight: this.$globalData.state.headerHeight,
      show: false,
      id: '',
      detail: {},
      failReason: '',
    }
  },
  onLoad(param) {
    this.id = param.id
    this.queryPublishInfo(this.id)
  },
  methods: {
    queryPublishInfo(id) {
      this.$request('/enterprisePublishApply/enterprisePublishApplyInfo', { id }).then((res) => {
        this.detail = res.result
      })
    },
    handleNavEnterDetail() {
      let url = `/pages/form/company`
      url += `?userId=${this.detail.userId}`
      this.$routeUtils.navigateTo({ url })
    },
    handleDelete() {
      const id = this.id
      this.$refs.dialog.confirm({
        title: '确认删除？',
        confirmBtnFn: () => {
          this.$request('/enterprisePublishApply/deleteEnterprisePublishApply', { id }).then(
            (res) => {
              this.$utils.toast('删除成功!')
              setTimeout(() => {
                uni.navigateBack({})
              }, 1500)
            },
          )
        },
      })
    },
    handleOutShelf() {
      const id = this.id
      this.$refs.dialog.confirm({
        title: '确认下架该企业需求？',
        confirmBtnFn: () => {
          this.$request('/enterprisePublishApply/offlineEnterprisePublishApply', { id }).then(
            (res) => {
              this.$utils.toast('下架成功!')
              setTimeout(() => {
                uni.navigateBack({})
              }, 1500)
            },
          )
        },
      })
    },
    refuseBtn() {
      this.show = true
    },
    confirmBtn() {
      this.auditPub(2)
    },
    cancelBtn() {
      this.show = false
    },
    auditPub(num) {
      this.$request('/enterprisePublishApply/auditEnterprisePublishApply', {
        id: this.id,
        audit: num,
        failReason: num == 2 ? this.failReason : undefined,
      }).then((res) => {
        this.$utils.toast(num == 1 ? '已通过' : '已拒绝')
        setTimeout(() => {
          uni.navigateBack({})
        }, 1000)
      })
    },
    goChat() {
      uni.setStorageSync('chatUser', {
        id: this.detail.userId,
        name: this.detail.enterpriseName,
        avatar: this.detail.avatar || '',
      })
      this.$routeUtils.navigateTo({
        url: `/pages/new/sendMsg?id=${this.detail.userId}&name=${this.detail.enterpriseName}`,
      })
    },
  },
}
</script>

<style scoped lang="scss">
.page-business {
  padding: 20rpx;
  .inner {
    border-radius: 10rpx;
    padding: 20rpx;
    .header-my {
      border-bottom: 1rpx solid #c8c7cc;
      padding-bottom: 20rpx;
      .title {
      }
    }
    .fail-reason {
      color: #f44336;
      margin-bottom: 30rpx;
    }
  }
}
.tags-item {
  margin-right: 15rpx;
  margin-top: 8rpx;
}
.tags-icon {
  margin-right: 8rpx;
}
.tags-list {
  margin-top: 10rpx;
}
.content-word {
  padding-top: 20rpx;
  text-indent: 40rpx;
  line-height: 1.8;
}
.foot-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9;
  background-color: #fff;
  padding-top: 10rpx;
  padding-bottom: calc(10rpx + env(safe-area-inset-bottom));
  justify-content: space-between;
  .btn {
    display: inline-flex;
    margin-right: 20rpx;
  }
}
.item-left {
  padding: 0 30rpx;
}
</style>
